package org.hydrakyoufeng.stuplatform.utils;

import org.springframework.stereotype.Component;

import java.math.BigInteger;
import java.security.MessageDigest;

@Component
public class Md5Utils {

    /**
     * 将byte数组进行md5编码
     * @param bytes
     * @return
     */
    public String encode(byte[] bytes) throws Exception {
    MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bytes);
            byte[] b = md.digest();
        BigInteger bi = new BigInteger(1, b);
        return bi.toString(16);
    }

    /**
     * 将字符串进行md5编码
     * @param value
     * @return
     * @throws Exception
     */
    public String encode(String value) throws Exception {
        return encode(value.getBytes());
    }
}
